﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

namespace Microsoft.SqlCommunity.SQLRSS
{
    /// <summary>
    /// This class represents a relational column in a table.
    /// </summary>
    public class ColumnDescription : Description
    {
        // The physical name of the column
        public string Name { get; set; }
        // The logical or descriptive name for the column.  This can also be used to disambiguate 
        // column names from distinct tables in database format strings.  See TableDescription.cs for more
        // on database format strings.
        public string DisplayName { get; set; }

        //Initialize an instance from an XML element which represents the column from the configuration file.
        public ColumnDescription(XElement columnElement)
        {
            Name = AttributeValueOrNull(columnElement, "Name");
            DisplayName = AttributeValueOrNull(columnElement, "DisplayName");

        }

        /// <summary>
        /// Determines if the name we're looking for is similar to either the name or display name
        /// of the column.
        /// </summary>
        /// <param name="testName">the name we're looking for</param>
        /// <returns>true if the name we're looking for is similar to the name or display name</returns>
        public bool IsGeneralNameMatch(string testName)
        {
            return (String.Compare(this.Name, testName, StringComparison.InvariantCultureIgnoreCase) == 0)
                                || (String.Compare(this.DisplayName, testName, StringComparison.InvariantCultureIgnoreCase) == 0);
        }
    }
}
